package com.itheima.泛型.sort;

import java.util.Set;
import java.util.TreeSet;

/**
 * @Author 王加鑫
 * @Date 2021/5/14 15:15
 * @Version 1.0
 */
public class TeacherTest {
    public static void main(String[] args) {
        Teacher teacher1 = new Teacher("zhangsan",25);
        Teacher teacher2 = new Teacher("lisi",23);
        Teacher teacher3 = new Teacher("wangwu",18);
        Teacher teacher4 = new Teacher("zhaoliu",25);

        Set<Teacher> set = new TreeSet<>((o1, o2) -> {
            int res = o1.getAge() - o2.getAge();
            res = res == 0 ? o1.getName().compareTo(o2.getName()) : res;
            return res;
        });
        set.add(teacher1);
        set.add(teacher2);
        set.add(teacher3);
        set.add(teacher4);

        System.out.println(set);
    }
}
